<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>(工资管理) - 发放学生工资</title>
    <link rel="stylesheet" href="../../dist/css/layui.css">
    <script src="../../dist/layui.js"></script>
    <script src="../../dist/jquery-1_8_3.js"></script>
    <style>
        body {
            background-color: burlywood;
        }

        .content {
            position: absolute;
            left: 35%;
            top: 50%;
            width: 60%;
            height: 60%;
            margin-left: -240px;
            margin-top: -200px;
            overflow: hidden;
            background-color: rgba(255, 250, 250, 20%);
            border-radius: 25px;
        }

        #content {
            position: absolute;
            left: 25%;
            top: 35%;
        }
        #tips {
            position: absolute;
            right: 2%;
            top: 2%;
        }
    </style>
</head>
<body>
<div class="content">
    <div id="tips">
        <span style="color: yellow; font-size: 12px">注意：本月操作的是上月的工资</span>
    </div>
    <div id="content">
        <div class="layui-inline">
            <label class="layui-form-label"><span style="color:white">操作年月:</span></label>
            <div class="layui-input-inline">
                <input type="text" id="timeChoice" class="layui-input" onfocus="this.type='text'" readonly placeholder="请选择年月" required>
            </div>
            <button id="submitButton" type="button" class="layui-btn layui-btn-normal">查询</button>
        </div>
        <div class="layui-form-item" style="margin-top: 10px">
            <label class="layui-form-label"><span style="color:white">结果:</span></label>
            <div class="layui-input-block">
                <input type="text" name="title" id="target" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item" id="controlBtn" style="margin-top: 10px; text-align: center">
        </div>
    </div>
</div>

<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
//年月选择器
        laydate.render({
            elem: '#timeChoice'
            , type: 'month'
            ,trigger: 'click'
            , max: 0
            , min: 1451577600
        });
    });

    // 查询工资情况
    $('#submitButton').on('click', function () {
        var date = $("#timeChoice").val();
        if (date !== '') {
            $.ajax({
                url: '/admin/selectSalaryStatusByDate?date=' + date,
                type: 'get',
                dataType: 'JSON',
                success: function (result) {
                    var controlBtn = $('#controlBtn');
                    if (result === 0) {
                        $('#target').val('操作月：' + date + "，未统计上月工资");
                        controlBtn.html('');
                        controlBtn.html('<button class="layui-btn" type="button" id="statisticSalary">统计工资</button>');

                    } else if (result === 1) {
                        $('#target').val('操作月：' + date + "，已统计上月工资");
                        controlBtn.html('');
                        controlBtn.html('<button class="layui-btn" type="button" id="sendSalary">发放工资</button>');
                    }
                }
            });
        }
    });

    // 统计工资
    $('#statisticSalary').live('click', function () {
        var date = $("#timeChoice").val();
        // layer询问
        layer.open({
            title: '统计工资确认',
            type: 0,
            content: '请问您真的要统计' + date + '的上一月工资吗？',
            icon: 3,
            yes: function (index, layero) {
                // 执行统计工资
                $.ajax({
                    url: '/admin/countSalaryByDate?date=' + date,
                    type: 'get',
                    dataType: 'JSON',
                    success: function (result) {
                        if (result === 0) {
                            layer.msg('操作失败，工资已统计', {
                                time: 2000
                            });
                        }
                        if (result === 1) {
                            layer.msg('操作成功', {
                                time: 800
                            });
                        }
                    }
                });
            }
        });
    });

    // 发放工资
    $('#sendSalary').live('click', function () {
        var date = $("#timeChoice").val();
        // layer询问
        layer.open({
            title: '发放工资确认',
            type: 0,
            content: '请问您真的要发放' + date + '的上一月工资吗？',
            icon: 3,
            yes: function (index, layero) {
                // 执行发放
                $.ajax({
                    url: '/admin/sendSalaryByDate?date=' + date,
                    type: 'get',
                    dataType: 'JSON',
                    success: function (result) {
                        if (result === 0) {
                            layer.msg('操作失败，工资已发放', {
                                time: 2000
                            });
                        }
                        if (result === 1) {
                            layer.msg('操作成功', {
                                time: 800
                            });
                        }
                    }
                });
            }
        });
    })

</script>
</body>
</html>